package com.ume.supplier.cn.httputil.http

import android.content.Context
import java.io.IOException
import java.net.ConnectException
import java.net.SocketTimeoutException

/**
 * Created by joe on 2018/7/2
 */
fun httpExceptionConvertString(context: Context, e: Throwable?): String? {
    if (!NetworkUtils.hasNetwork(context.applicationContext)) {
        return "无网络链接，请检查网络"
    }

    if (e is ConnectException) {
        return "服务器连接失败"
    }

    if (e is SocketTimeoutException) {
        return "服务器连接超时"
    }

    if (e is IOException) {
        return "服务器连接异常"
    }

    if (e is NumberFormatException) {
        return "数据类型转换异常"
    }
    if (e is RespException) {
        return e.message
    }

    return null
}